home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3115 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  54 lines

  1. Path: svnews.ubinet.ubs.com!ubszh!ubszh!jis
  2. From: jis@ubszh.net.ch (Johnston Ian (by ubsswop))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: maddening constructor problem
  5. Date: 22 Jan 1996 10:31:43 GMT
  6. Organization: UBS
  7. Distribution: world
  8. Message-ID: <4dvp2f$rbd@ubszh.fh.zh.ubs.com>
  9. References: <4dr307$4so@noc2.drexel.edu>
  10. NNTP-Posting-Host: nol2179.fh.zh.ubs.com
  11.  
  12. In article <4dr307$4so@noc2.drexel.edu>, st918h5w@dunx1.ocs.drexel.edu (Jonathan Juniman) writes:
  13. |> Maddening constructor problem:
  14. |> 
  15. |> MYCLASS.H
  16. |> class MyClass
  17. |>     {
  18. |>     public:
  19. |>     MyClass(unsigned int i, insigned int j, double* pK);
  20. |>     // etc
  21. |>     }
  22. |> 
  23. |> MYCLASS.CPP
  24. |> MyClass::MyClass(unsigned int i, unsigned int j, double* pK)
  25. |>     {
  26. |>     // constructor code here
  27. |>     }
  28. |> 
  29. |> Visual C++ bites me on MYCLASS.CPP, saying "constructor not allowed
  30. |> a return type".  What's the problem?  The constructor doesn't _have_
  31. |> a return type. Please respond by e-mail.
  32.  
  33. Almost certainly a missing semi-colon on a class or struct declaration
  34. immediately preceding the constructor (*after* preprocessing).
  35.  
  36. For example:
  37.  
  38. struct X
  39. {
  40.     X();
  41. }
  42.  
  43. X::X()
  44. {
  45. }
  46.  
  47.  
  48. Without the semi-colon, the compiler sees the struct declaration as the
  49. return type.
  50.  
  51. Ian
  52.  
  53.  
  54.